package 异常;

import javax.crypto.spec.PSource;
import java.util.Scanner;

public class 练习 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        //1.创建女朋友的信息
        GirlFried gf=new GirlFried();

        //2.键盘录入女朋友的姓名
        while (true) {
            try {
                System.out.print("请输入姓名:");
                String name = sc.nextLine();
                gf.setName(name);

                //3.键盘录入女朋友的年龄
                System.out.print("请输入年龄:");
                String ageStr = sc.nextLine();
                int age = Integer.parseInt(ageStr);
                gf.setAge(age);

                //年龄和姓名输入正确跳出循环
                break;
            } catch (NumberFormatException e) {
                System.out.println("年龄的格式错误,请输入正确的格式");
            }catch (NameFortException | AgeOutBoundException e){
                e.printStackTrace();
            }
        }

        //5.打印女朋友的信息
        System.out.println(gf);
    }
}
